/** @format */

// 批量注册自定义组件
// Author 区区电脑
// Email 1573580882@qq.com
// Date 2023-01-27
// Copyright © 2023 gys. All rights reserved.
import {defineAsyncComponent} from "vue";

const modules = {
    ...import.meta.glob("./*/*.vue"),
    ...import.meta.glob("./*/*.jsx"),
};
//const componentConfig = {};
//for (const path in modules) {
//    const name = path.split("/").at(-1).split(".")[0];
//    componentConfig[name] = modules[name];
//}

export default function registerCustomComponents(app) {
    for (const path in modules) {
        const type = path.split("/").at(-1).split(".")[1];
        const name = path.split("/").at(-1).split(".")[0];
        const beforePath = path.split("/").at(-2);
        if (type === "vue") {
            app.component(
                name,
                defineAsyncComponent(() => import(`./${beforePath}/${name}.vue`))
            );
        } else if (type === "jsx") {
            app.component(
                name,
                defineAsyncComponent(() => import(`./${beforePath}/${name}.jsx`))
            );
        }

    }
}
